package com.cn.fw4j.util;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashSet;
import java.util.Properties;
import java.util.Set;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.cn.fw4j.container.impl.JavaController;



public class ScanningFileHelper {
	private static Set<String> fileSet = new HashSet<String>();
	private final static Logger logger = LoggerFactory.getLogger(JavaController.class);
	
	static{
		String path = System.getProperty("user.dir");
		scanning(path);
//		String path = Thread.currentThread().getContextClassLoader().getResource("/").getPath();
//		InputStream input = Thread.currentThread().getContextClassLoader().getResourceAsStream("fw4j.properties");
//		Properties p = new Properties();
//		try {
//			if(input != null){
//				p.load(input);
//				if (p.containsKey("FW4J_DIR")) {
//					path = System.getProperty((String)p.get("FW4J_DIR"));
//				}
//			}
//		} catch (IOException e) {
//		}
//		finally{
//			scanning(path);
//		}
	}
	
	public static Set<String> getFileSet() {
		return fileSet;
	}

	public static final void scanning(String pg) {
	        File file = new File(pg); 
	        File[] childFiles = file.listFiles();
	        for (File childFile : childFiles) { 
	            if (childFile.isDirectory()) { 
	                 scanning(childFile.getPath()); 
	            } else { 
	                String childFilePath = childFile.getPath(); 
	                fileSet.add(childFilePath);
	            }
	        } 
	}
}
